<?php

 include ('style/top.php');
 include ('style/menu.php');
 include ('style/left.php');

?>

    
 <?php 
   if(isset($_GET['categories']) ){

            $xemsp = $_GET['categories'];
            
            
// bắt đầu breadcrum
        $sql = "select d.id,d.tendm FROM sanpham AS s INNER JOIN hangsanxuat AS h ON s.mahangsx_id = h.id INNER JOIN danhmuc as d ON s.danhmuc_id = d.id WHERE d.id =".$xemsp;
        $q = mysql_query($sql);
        
        $row = mysql_fetch_array($q);
       
        $iddm = $row['id'];
        $tendm = $row['tendm'];            
               
 
        echo "<div class='content'>";
        
        
        echo " <div id='contentop'>";
        echo " <div class='logohinhtop'></div>";
        echo " <div class='khungchutop'>";
        echo " <div id='chu'><a href = 'index.php'>Trang chủ</a><img src='images/arrow.png' /><a href='sanpham.php?categories=".$iddm."'>$tendm</a></div>";
        echo "     </div>";   
        echo "  </div>";
    
            
     // kết thúc breacrum
            
?>
<?php     
              
            
            // phâm trang 
            $sl = "SELECT COUNT(s.ID) FROM sanpham AS s INNER JOIN hangsanxuat AS h ON s.mahangsx_id = h.id INNER JOIN danhmuc as d ON d.id = s.danhmuc_id WHERE d.id = ".$xemsp;
            
            $qr = mysql_query($sl) or die ("không đếm được id sản phẩm".mysql_error());
            
            $num = mysql_fetch_row($qr);
            
            // kết quả số dòng trả về
            $resul_num = $num[0];
            // đặt số dòng hiển thị
            
            $row_hienthi= 9;
            
            
            // tính số trang hiển thị
            $num_per_page = ceil($resul_num/$row_hienthi);
            
            $page = isset($_GET['page'])?$_GET['page']:1;
            
            if( $page > $num_per_page ) $page = $num_per_page;
             if ( $page < 1 ) $page = 1;
             
             // tính vị trí bắt đầu
             $start = ($page - 1)* $row_hienthi;
            
            
            
            
            $sql = "SELECT h.logo_hang,s.id,s.tensp,s.hinhanh,s.dongia,s.baohanh FROM sanpham AS s INNER JOIN hangsanxuat AS h ON s.mahangsx_id = h.id INNER JOIN danhmuc as d ON d.id = s.danhmuc_id WHERE d.id = ".$xemsp." LIMIT $start, $row_hienthi";
            
            $querysl = mysql_query($sql) or die("không thực hiện được".mysql_error());
        
                while($hienthi = mysql_fetch_array($querysl)){
            
                     $idsp = $hienthi['id'];
            
                    $logohang = $hienthi['logo_hang'];
            
                    $tensp = $hienthi['tensp'];
            
                    $hinhanhsp = $hienthi['hinhanh'];
            
                    $dongiasp = $hienthi['dongia'];
            
                    $baohanh = $hienthi['baohanh'];
            
            
    echo "<div class=\"product\">\n"; 
    echo "    	\n"; 
    echo "     <div class =\"supplier\">\n"; 
    echo "        <div class=\"suplierimg\"> \n"; 
    echo "            <img style ='width : 91px; height: 22px;' src=\"$logohang\"/>\n"; 
    echo "        </div>\n"; 
    echo "        <div class=\"#\">\n"; 
    echo "            \n"; 
    echo "        </div>\n"; 
    echo "     </div>       \n"; 
    echo "     <div class=\"khungtieudesp\">\n"; 
    echo "        <div class=\"tieudesp\">$tensp</div>\n"; 
    echo "     </div>\n"; 
    echo "     <div class=\"khungsp\" align=\"center\">\n"; 
    echo "        <div class=\"hinhsp\"><img style ='width : 120px; height : 100px;' src=\"$hinhanhsp\"/></div>\n"; 
    echo "     </div>\n"; 
    echo "     <div class= \"khungpri\" align=\"center\">\n"; 
    echo "    	<span class=\"spanpri\"><div class=\"noidungpri\"> Giá :</div> <div class=\"fontpri\">".convert_money($dongiasp)."</div> <div class=\"noidungpri\">VNĐ</div></span>\n"; 
    echo "     </div>\n"; 
    echo "     <div class=\"baohanh\">\n"; 
    echo "        <div class=\"fontbaohanh\">Bảo hành : $baohanh tháng</div>\n"; 
    echo "     </div>\n"; 
    echo "     <div class='chitietsp'><a href = 'chitietsanpham.php?chitietspid=".$idsp."'><img class='chitietimg' src='images/chitiet.jpg' /></a></div>"; 
    echo "     </div>\n";      
        
        
        }
        
        // xử lý phân trang
        echo "<div class ='phantrang'>"; 
        echo "<ul>";
        echo "<li class ='fonttrang'> Trang : ";
        for($i =1;$i<=$num_per_page;$i++){
		if($page!=$i){
            echo "<a class ='sotrang' href='?categories=".$xemsp."&page= $i' title ='Trang $i'>$i</a>";
         
         }
		else{
  		
  	     echo "<a class ='tranghienthi'>$i</a>";
		}	

	   }
        echo "</li>";
        echo "</ul>";
        echo "</div>"; 
        
        echo "</div>"; 
       } else{
            echo " Chủng Loại chưa có sản phẩm ";
        }
        
        
  
     
    ?>

 <?php


 include ('style/right.php');
 include ('style/bottom.php');

?>